# Copyright 2024 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

"""Bazel module configuration for IREE."""

module(
    name = "iree_core",
    version = "0.0.1",
)

# Core Bazel dependencies - versions aligned with LLVM's MODULE.bazel
bazel_dep(name = "apple_support", version = "1.24.1", repo_name = "build_bazel_apple_support")
bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "rules_cc", version = "0.2.11")
bazel_dep(name = "rules_python", version = "1.6.3")

# Python pip dependencies
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
    hub_name = "pip",
    python_version = "3.11",
    requirements_lock = "//build_tools/bazel:requirements.txt",
)
use_repo(pip, "pip")

bazel_dep(name = "rules_shell", version = "0.6.1")

# Required by LLVM (for clang-fuzzer tools)
bazel_dep(name = "protobuf", version = "31.1", repo_name = "com_google_protobuf")

# LLVM also needs these
bazel_dep(name = "rules_android", version = "0.6.6")
bazel_dep(name = "rules_foreign_cc", version = "0.15.1")
bazel_dep(name = "zlib-ng", version = "2.0.7", repo_name = "llvm_zlib")
bazel_dep(name = "zstd", version = "1.5.7", repo_name = "llvm_zstd")

# Stack trace support on Linux.
bazel_dep(name = "libbacktrace", version = "1.0.0-20250926-7939218")

# LLVM project overlay module
bazel_dep(name = "llvm-project-overlay", version = "main")
local_path_override(
    module_name = "llvm-project-overlay",
    path = "third_party/llvm-project/utils/bazel",
)

# Use LLVM's extension for third-party dependencies
llvm_repos_ext = use_extension(
    "@llvm-project-overlay//:extensions.bzl",
    "llvm_repos_extension",
)
use_repo(
    llvm_repos_ext,
    "gmp",
    "mpc",
    "mpfr",
    "nanobind",
    "pfm",
    "pybind11",
    "pyyaml",
    "robin_map",
    # Note: vulkan_headers is provided by iree_ext with IREE's custom BUILD.overlay
    "vulkan_sdk",
)

# IREE extension creates llvm-raw (when IREE is root) and other IREE-specific repos
iree_ext = use_extension("//build_tools/bazel:extensions.bzl", "iree_extension")
use_repo(
    iree_ext,
    "com_github_dvidelabs_flatcc",
    "com_google_benchmark",
    "com_google_googletest",
    "hsa_runtime_headers",
    "iree_cuda",
    "llvm-raw",
    "nccl",
    "spirv_cross",
    "stablehlo",
    "tracy_client",
    "vulkan_headers",
    "webgpu_headers",
)

# Configure LLVM using the llvm-raw repo (creates llvm-project)
llvm_configure = use_repo_rule("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure")

llvm_configure(name = "llvm-project")
